/*
  JavaScript code for compare.html
*/

chrome.tabs.getCurrent((function(tab){
	if(tab)
		chrome.browserAction.setPopup({tabId: tab.id, popup: "popup_compare.html"});
}));

function setDirection(dir)
{
	var frameset = document.getElementById("frameset");
	if(dir == "lr")
	{
		frameset.cols = "50%,50%";
		frameset.rows = "";
	}
	else if(dir == "tb")
	{
		frameset.rows = "50%,50%";
		frameset.cols = "";
	}
}

function updateUrl(frameId, url)
{
	if(frameId == 1)
		document.getElementById("frame1").src = url;
	else if(frameId == 2)
		document.getElementById("frame2").src = url;
}

document.addEventListener("load", (function(){
var frame1 = document.getElementById("frame1");
var frame2 = document.getElementById("frame2");
var q = location.search ? location.search.substr(1).split("&") : [];
var params = [];
for(var i = 0; i < q.length; ++i)
{
	var cur = q[i].split("=");
	cur[0] && (params[cur[0]] = cur[1]);
}

if(!params["compareInfo"])
	return;
var compareInfo = JSON.parse(unescape(params["compareInfo"]));
setDirection(compareInfo.direction);
if(frame1 && compareInfo.urls[0] && frame1.src == "about:blank")
	frame1.src = compareInfo.urls[0];
if(frame2 && compareInfo.urls[1] && frame2.src == "about:blank")
	frame2.src = compareInfo.urls[1];
}), true);

chrome.extension.onRequest.addListener((function(request, sender, sendResponse)
{
	if(request && request.command == "update" && request.details)
	{
	}
}));